package com.bgy.geek.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bgy.geek.dao.TbProjectDao;
import com.bgy.geek.dao.TbResourceDao;
import com.bgy.geek.dao.TbUserDao;
import com.bgy.geek.entity.TbProject;
import com.bgy.geek.entity.TbResource;
import com.bgy.geek.entity.TbUser;
import com.bgy.geek.service.TbResourceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 资源表(TbResource)表服务实现类
 *
 * @author makejava
 * @since 2021-10-21 23:24:33
 */
@Service("tbResourceService")
public class TbResourceServiceImpl extends ServiceImpl<TbResourceDao, TbResource> implements TbResourceService {

	@Resource
	private TbResourceDao resourceDao;
	@Resource
	private TbUserDao userDao;
	@Resource
	private TbProjectDao projectDao;

	/**
	 * 根据用户bip和对应的项目新增资源表
	 * @param map
	 * @return
	 */
	@Override
	public Boolean insertResourceByBip(Map<String, List<String>> map) {
		if (CollectionUtil.isNotEmpty(map)) {
			map.forEach((k,v)->{
				//根据bip查出人员信息
				TbUser tbUser = userDao.selectOne(new QueryWrapper<TbUser>().lambda().eq(TbUser::getBip, k));
				if (tbUser == null) {
					throw new RuntimeException("用户不存在");
				}
				//查出项目信息
				v.forEach(projectCode -> {
					TbProject project = projectDao.selectOne(new QueryWrapper<TbProject>().lambda().eq(TbProject::getProjectCode, projectCode));
					//插入资源表
					TbResource tbResource = new TbResource();
					//TODO 待维护
				});
			});
		}
		return Boolean.FALSE;
	}
}
